#------------------------------
# Game States.
#------------------------------
class GameState(object):
    def __init__(self):
        self.current_state = None
        self.state_sequence = [     GameIn(), 
                                    GameBoardSent(),
                                    GameBattle()    ]
        
    def next_state(self):
        
        if not self.current_state:
            #"Player entered game."
            self.current_state = self.state_sequence[0]
            return
            
        elif type( self.current_state ) == type( self.state_sequence[0] ):
            #"Both players in. Sending boards."
            self.current_state = self.state_sequence[1]
            return
            
        elif type( self.current_state ) == type( self.state_sequence[1] ):
            #"About to place last boat, prepare for battle."
            self.current_state = self.state_sequence[2] 
            return
        
        elif type( self.current_state ) == type( self.state_sequence[2] ):
            #"Battle over, resetting game. Back to place boats."
            self.current_state = self.state_sequence[1]
            return
            
        else:
            print "Invalid state change."
            raise
    
    def end_game(self):
        print "Game has ended."
        self.current_state = GameOver()
    
    def get_state(self):        
        if isinstance( self.current_state, GameIn ): return 1 
        elif isinstance( self.current_state, GameBoardSent ): return 2
        elif isinstance( self.current_state, GameBattle ): return 3
        elif isinstance( self.current_state, GameOver ): return 4
        else:
            return 0
         

#=======================================================================================================================
# Available states
#=======================================================================================================================
class SBSState(object):
    def __init__(self):
        self.tick = 0
    
    def tick_me(self):
        if self.tick == 0: 
            self.tick = 1
        else: 
            self.tick = 0

class GameIn(SBSState):
    ''' Ticks if one player has entered. '''
    pass

class GameBoardSent(SBSState):
    ''' Ticks if one board is sent. ''' 
    pass

class GameBattle(SBSState):
    ''' Ticks if one player is done battling'''
    pass

class GameOver(SBSState):
    ''' Final state. '''
    pass

